package com.bipa.dao;

import com.bipa.bean.Order;
import com.bipa.bean.OrderItem;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderDao {

    //保存订单信息 并获取订单的主键值id
    @Options(useGeneratedKeys=true,keyProperty="id")
    @Insert("insert into ec_order(order_code,create_date,amount,user_id) values(#{order_code},#{create_date},#{amount},#{user_id})")
    public int saveOrder(Order order);

    //保存订单明细
    @Insert("insert into ec_order_item(order_id,article_id,order_num) values(#{order_id},#{article_id},#{order_num})")
    public void saveItem(@Param("order_id") int order_id,@Param("article_id") int article_id,@Param("order_num") int order_num);

    //1、根据用户的id查询订单表（ec_order）
    @Select("select * from ec_order where user_id = #{id}")
    public List<Order> getOrdersByUserId(int id);

    //根据订单id获取订单详情信息
    @Select("SELECT * FROM ec_order_item WHERE order_id = #{id}")
    public List<OrderItem> getItemsByOrderId(@Param("id") int id);

    @Select("select * from ec_order WHERE payStatus LIKE CONCAT('%',#{paystatus},'%') AND order_code LIKE CONCAT('%',#{order_code},'%')")
    public List<Order> getAll(@Param("paystatus") String paystatus,@Param("order_code")String order_code);

    //分页查询
    @Select("SELECT * FROM ec_order WHERE payStatus LIKE CONCAT('%',#{paystatus},'%') AND order_code LIKE CONCAT('%',#{order_code},'%') limit #{startSize},#{pageSize}")
    public List<Order> findAllOrders(@Param("paystatus") String paystatus,@Param("order_code")String order_code,@Param("startSize")Integer startSize,@Param("pageSize")Integer pageSize);

    @Update("update ec_order set send_date = #{send_date} , status = #{status} where id = #{id}")
    public void checkOrder(@Param("id")Integer id,@Param("status")Integer status,@Param("send_date")java.util.Date send_date);
}
